Skip to content

handle connection close on CancelledError to prevent stale results #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

shenchucheng
Copy link

Description

This PR resolves an issue where canceled queries using connections from a pool leave unintended results that affect subsequent queries. When a query is canceled, the connection is returned to the pool without proper cleanup, causing future queries to receive residual data from the canceled task.

Solution

  • Implemented _close_on_cancel to ensure that connections are fully closed and reset when a query is canceled.
  • Added a test case to verify that canceled queries do not impact future connections from the pool.

This update ensures clean connection states on cancellation, improving reliability in pooled query operations. This approach is inspired by similar handling in aiomysql

Related Issues

@long2ice
Copy link
Owner

Please run make style ci in local first

@shenchucheng
Copy link
Author

Please run make style ci in local first

Okay, I've updated it. Please check again.

@long2ice long2ice force-pushed the dev branch 3 times, most recently from a036841 to 6c16f3b Compare December 12, 2024 14:07
elbaro added a commit to elbaro/asyncmy that referenced this pull request Aug 2, 2025
@StrayDragon
Copy link

Cool, we need this fix, could you please prioritize it? I have to use a forked version now cannot receive update friendly ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants